package com.ruoyi.api.service.impl;


import com.ruoyi.api.service.CollectApiService;
import com.ruoyi.api.utils.SysCollect;
import com.ruoyi.api.vo.ApiDemo;
import com.ruoyi.api.vo.CollectApi;

import com.ruoyi.vim.mapper.CollectApiMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CollectApiServieImpl implements CollectApiService {

    @Autowired
    private CollectApiMapper collectApiMapper;

    @Override
    public boolean insertCollect(ApiDemo apiDemo) {
        SysCollect sysCollect = new SysCollect();
        CollectApi collectApi = sysCollect.sysCollects(apiDemo);
        boolean a = collectApiMapper.insertApi(collectApi);
        return a;
    }

    @Override
    public List<ApiDemo> selectCollect(String id) {
        List<CollectApi> collectApi = collectApiMapper.selectByid(id);
        List<ApiDemo> list = new ArrayList<>();
        SysCollect sysCollect = new SysCollect();
        for (CollectApi api : collectApi) {
            list.add(sysCollect.sysApiDemo(api));
        }
        return list;
    }

    @Override
    public void delectCollect(String id) {
        collectApiMapper.deleteByIds(id);
    }

    @Override
    public void updateCollect(ApiDemo apiDemo)
    {
        SysCollect sysCollect = new SysCollect();
        CollectApi collectApi = sysCollect.sysCollects(apiDemo);
        collectApiMapper.updateByIds(collectApi);
    }
}
